#include <QJsonArray>
#include <QJsonObject>
#include <QList>
#include <QOBject>
#include <QJsonDocument>
#ifndef TREESELECT_H
#define TREESELECT_H

#endif // TREESELECT_H

class TreeSelect{
public:
    int id;
    QString label;
    QList<TreeSelect> children;
    QJsonObject toJsonObject(){
        QJsonObject obj;
        obj.insert("id",id);
        obj.insert("label",label);
        QJsonArray arrChildren;
        for(int i = 0;i< children.size();i++){
            children[i].toJsonObject();
            arrChildren.append(children[i].toJsonObject());
        }
        obj.insert("children",arrChildren);
        return obj;
    }
    static TreeSelect toTreeSelect(const QJsonObject& json) {
        TreeSelect treeSelect;
        treeSelect.id = json["id"].toInt();
        treeSelect.label = json["label"].toString();

        // 解析permissions
        QJsonArray childrenArray = json["children"].toArray();
        for (const QJsonValue& value : childrenArray) {
            QJsonObject child = value.toObject();
            TreeSelect item = toTreeSelect(child);
            treeSelect.children.append(item);
        }

        return treeSelect;
    }
};
